#ifndef _THREAD_POOL_H_
#define _THREAD_POOL_H_

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <mlog.h>
#include "define.h"

#define POOLLOGFILE LOGDIR"/thread_pool.log"

/*job struct*/
typedef struct job
{
    void *(*process)(void *arg);
    void *arg;
    struct job * next;
}Job;

typedef struct thread_pool{
    pthread_mutex_t pool_lock;
    pthread_cond_t job_ready;
    Job *jobs;
    int destory;
    pthread_t *threads;
    unsigned int thread_num;
    int size;
}Thread_pool;

#ifdef __cplusplus
    extern "C" {
#endif

int pool_init(unsigned int);
int pool_add_job(void *(*process)(void *),void *);
int pool_destory(void);
void *routine(void *);

#ifdef __cplusplus
    }
#endif
#endif
